package com.itheima.mapper;

import com.itheima.pojo.Student;
import org.apache.ibatis.annotations.*;
import org.springframework.web.bind.annotation.PathVariable;

import java.util.List;
import java.util.Map;

@Mapper
public interface StudentsMapper {
    /**
     * 分页查询
     * @param name
     * @param degree
     * @param clazzId
     * @return
     */
    List<Student> list(String name, Integer degree, Integer clazzId);


    /**
     * 根据id查询学生信息
     * @param id
     * @return
     */
    @Select("select * from student where id = #{id}")
    Student getInfo(Integer id);

    /**
     * 修改学生信息
     * @param student
     */
    void update(Student student);

    /**
     * 扣分
     * @param id
     * @param score
     */
    @Update("update student set " +
            "violation_score = violation_score + #{score}, " +
            "violation_count = violation_count + 1, " +
            "update_time = now() " +
            "where id = #{id}")
    void deduct(@Param("id") Integer id, @Param("score") Integer score);

    /**
     * 新增学员信息
     * @param student
     */
    void add(Student student);

    /**
     * 删除学员信息
     * @param ids
     */
    void delete(List<Integer> ids);

    /**
     * 统计班级人数
     * @return
     */
    @Select("select c.name cname , count(s.id) scount from clazz c  left join student s on s.clazz_id = c.id group by c.name order by count(s.id) desc ")
    List<Map<String, Object>> getStudentCount();

    /**
     * 统计各学历人数
     * @return
     */
    @MapKey("name")
    List<Map> countStudentDegreeData();
}
